import React, { Component } from "react";

import {
  BrowserRouter as Router,
  Redirect,
  Route,
  Switch,
} from "react-router-dom";

import Home from "./pages/Home";
import CityList from "./pages/CityList";
import Map from "./pages/Map";
import HouseDetail from "./pages/detail";
import { connect } from "react-redux";
import { update } from "./redux/actions/getCurCity_action";
import LoginAndRegister from "./pages/LoginAndRegister";
import getCurCity from "./utils/getCity";
import RentAdd from "./pages/RentAdd";
import RentList from "./pages/RentList";
import AuthRoute from "./compoents/AuthRoute";
class App extends Component {
  componentDidMount() {
    getCurCity().then((result) => {
      this.props.uppCity(result);
    });
  }

  render() {
    return (
      <div className="App">
        <Router>
          {/* 配置导航菜单 */}

          {/* 配置路由 */}
          <Switch>
            <Route path="/home" component={Home}></Route>
            <Route path="/loginOrRegister" component={LoginAndRegister}></Route>
            <Route path="/cityList" component={CityList}></Route>
            <Route path="/map" component={Map}></Route>
            <AuthRoute path="/rent/add" component={RentAdd}></AuthRoute>
            <AuthRoute path="/rent/list" component={RentList}></AuthRoute>
            <Route path="/house-detail/:id" component={HouseDetail}></Route>
            <Redirect path="/" to="/home"></Redirect>
          </Switch>
        </Router>
      </div>
    );
  }
}

export default connect(
  (state) => {
    return { curCity: state.curCity };
  },
  {
    uppCity: update,
  }
)(App);
